import Role from '../Role';
import Sprite from '../../base/Sprite';
import RoleAction from '../../../../Enum/roleAction'

const RoleKey = 'Iori'

/*
    八神类
 */
export default class Iori extends Role {
    constructor(props) {
        let img = Sprite.getImage(RoleKey);
        super({ img, ...props });
        this.roleKey = RoleKey;
        // 获取八神的精灵图
        let staticRole = this.roleConf[this.roleKey][this.state];
        this.width = Math.max(...staticRole.map(img => img.W));
        this.height = Math.max(...staticRole.map(img => img.H));
        this.index = 0; // 图片索引
    }
    // 绘制八神的各种状态
    draw() {
        let staticRole = this.roleConf[this.roleKey][this.state];
        // let maxH = Math.max(...staticRole.map(img => img.H));
        let maxW = Math.max(...staticRole.map(img => img.W));
        let currentImg = staticRole[Math.floor(this.index)];
        if (!currentImg) {
            return
        }
        const { x, y, W, H } = currentImg;
        this.width = W;
        this.height = H;
        super.draw(true);
        if (this.x < 0) {
            this.x = 0;
        }
        let pos = {
            y: this.canvas.height - this.height + (this.y),
            x: this.x,
        }
        // 处理跑步的x差
        if (this.state === RoleAction[3]) {
            pos.x = this.x + (maxW - W);
        }
        // 动画单次播放
        this.ctx.drawImage(
            this.img,
            x, y,
            W, H,
            pos.x, pos.y,
            this.width, this.height
        );
        
        // 绘制角色轮廓
        // this.ctx.strokeStyle = 'red';
        // this.ctx.strokeRect(
        //     pos.x, pos.y,
        //     this.width, this.height
        // )
    }
    show() {
        super.show();
    }
}
